$(function() {
	$('#datepicker').datepicker({
		changeMonth : true,
		changeYear : true,
		dateFormat : 'yy-mm-dd',
		minDate : new Date(),
		maxDate : '+1m',
		showButtonPanel : true,
		currentText : 'Today'
	}).tooltip();
	$('#timepicker_start').timepicker({
		minuteStep : 30,
		defaultTime : '09:00 AM'
	}).tooltip();
	$('#timepicker_end').timepicker({
		minuteStep : 30,
		defaultTime : '06:00 PM'
	}).tooltip();
	$('#h-slider').slider({
		range : "min",
		min : 0,
		max : 8,
		value : 4,
		slide : function(event, ui) {
			$("#amount").text(ui.value / 2);
		}
	}).tooltip();
	$('#amount').tooltip();
	$('#datepicker').datepicker('setDate', new Date());
	$("#query_time").click(function() {
		$.get("/book/time", {
			date : $("#datepicker").val(),
			beginTime : $("#timepicker_start").val(),
			endTime : $("#timepicker_end").val(),
			amount : $("#amount").text()
		}, function(result) {
			alert(result);
		});
	});
	if (document.getElementById("tabs")) {
		$("#tabs").tabs();
		$.get("/meetings/all", function(result) {
			var $a = $(result[0]);
			var $b = $(result[1]);
			var floor=1;
			var html="";
			$a.each(function() {
				if($(this)[0].floor!=floor){
					floor=$(this)[0].floor;
					html+="<br/>"
				}
				html=html+"<div class='span3' >"+$(this)[0].building+$(this)[0].floor+$(this)[0].number+"</div>";
			});
			$("#tabs-a").html(html);
			 floor=1
			 html="";
			$b.each(function() {
				if($(this)[0].floor!=floor){
					floor=$(this)[0].floor;
					html+="<br/>"
				}
				html=html+"<div class='span3' >"+$(this)[0].building+$(this)[0].floor+$(this)[0].number+"</div>";
			});
			$("#tabs-b").html(html);
		});
	}
});